# include <bits/stdc++.h>
# define INF 0x7fffffff
using namespace std;
map <int, int> a;
int op[500], val[500], avl[500];
int main() {
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        cin >> op[i] >> val[i];
        avl[i] = val[i];
    }
    sort(avl + 1, avl + n + 1);
    for(int i = 1; i <= n; i++) {
        a[avl[i]] = ++cnt;
    }
    cout << n << endl;
    for(int i = 1; i <= n; i++) {
        cout << op[i] << " " << ((op[i] == 4) ? val[i] : a[val[i]]) << endl;
    }
}
